/* eslint-disable global-require */
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import VueCookies from 'vue-cookies';

Vue.use(VueI18n);
Vue.use(VueCookies);

const CACHE_NAME = 'otLanguage';

const i18n = new VueI18n({
  locale: VueCookies.get(CACHE_NAME) || 'en-US',
  messages: {
    'en-US': require('@/locales/en-US.json'),
    'zh-CN': require('@/locales/zh-CN.json'),
  },
});

export const switchLang = (lang) => {
  i18n.locale = lang;
  VueCookies.set(CACHE_NAME, lang, 3600 * 24 * 365, '/', '.openocean.finance');
  VueCookies.set('userLanguage', lang === 'en-US' ? 'en' : lang, 3600 * 24 * 365, '/', '.openocean.finance');
};

export const getLanguages = () => [
  {
    label: 'English',
    value: 'en-US',
  },
  {
    label: '简体中文',
    value: 'zh-CN',
  },
];

export default i18n;
